home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Disc to the Future 2
/
Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin
/
MAC
/
THINKC
/
4_0
/
LIFER__
/
PROTO
/
P
/
PMD_LIFE.C
< prev
next >
Wrap
Text File
|
1991-07-23
|
11KB
|
272 lines
/* PMD_LIFE_WINDOW */
/* File name: LIFE_WINDOW */
/* Function: Handle a modeless dialog */
/* This dialog operates like a window, it is not modal. */
/* Opened by: */
/* Closed by: */
/* Purpose: */
/* History: 7/23/91 Original by Prototyper 3.0 */
#include "PCommonLife.h" /* Common */
#include "Common_Life.h" /* Common */
#include "PUtils_Life.h" /* General Utilities */
#include "Utils_Life.h" /* General Utilities */
#include "PA_Life_Alert.h" /* Alert */
#include "PD_LIFE_INPUT.h" /* Modal Dialog */
#include "LIFE_WINDOW.h" /* This specific modeless dialog */
#include "PMD_LIFE_WINDOW.h" /* This modeless dialog */
static Boolean ExitDialog; /* Flag to exit dialog */
/* ======================================================= */
/* ======================================================= */
/* This procedures purpose is to set the window pointer to nil, */
/* this is used to tell the other routines in this unit that this */
/* modeless dialog is not yet active (open). The other routines */
/* will then just return when called, without doing anything. */
void Init_LIFE_WINDOW()
{
Rect tempRect; /* Temporary rectangle */
short DType; /* Type of dialog item */
short Index; /* For looping */
Handle DItem; /* Handle to the dialog item */
ControlHandle CItem, CTempItem; /* Control handle */
Str255 sTemp; /* Get text entered, temp holding */
short itemHit; /* Get selection */
short temp; /* Get selection, temp holding */
WPtr_LIFE_WINDOW = NIL; /* Initialize to say that the dialog is not yet active */
U_Init_LIFE_WINDOW(); /* Call the user init routine */
}
/* ======================================================= */
/* Routine: Moved_LIFE_WINDOW */
/* Purpose: We were moved, possibly to another screen and screen depth */
void Moved_LIFE_WINDOW(OldRect, theWindow) /* Moved this window */
Rect *OldRect;
WindowPtr theWindow;
{
WindowPtr SavePort; /* Place to save the last port */
if (WPtr_LIFE_WINDOW == theWindow) /* Only do if the window is us */
{
GetPort(&SavePort); /* Save the current port */
SetPort(WPtr_LIFE_WINDOW); /* Set the port to my window */
U_Moved_LIFE_WINDOW(WPtr_LIFE_WINDOW,OldRect);/* Call user routine when we are moved */
SetPort(SavePort); /* Restore the old port */
} /* End for window is us */
} /* End of procedure */
/* ======================================================= */
/* This procedures purpose is to refresh this window, update it, */
/* when we are uncovered by another window. All of the non-controls */
/* are in this routine, such as rectangles and lines. Note that the */
/* Open routine calls this one to draw all of the non-controls. */
void Update_LIFE_WINDOW(theWindow)
WindowPtr theWindow;
{
GrafPtr SavedPort; /* Save the current port so we can restore to it */
Rect tempRect; /* Temporary rectangle variable */
short DType; /* Type of dialog item */
Handle DItem; /* Handle to the dialog item */
ControlHandle CItem; /* Control handle */
if ((WPtr_LIFE_WINDOW != NIL) && (theWindow == WPtr_LIFE_WINDOW))/* Only do if we are the window to update */
{ /* Start the update procedure */
GetPort(&SavedPort); /* Get the current port */
SetPort(WPtr_LIFE_WINDOW); /* Point to our port for drawing in our window */
GetDItem(WPtr_LIFE_WINDOW,Res_Dlg_Continue,&DType,&DItem,&tempRect);/* Get the item handle */
PenSize(3, 3); /* Change pen to draw thick default outline */
InsetRect(&tempRect, -4, -4); /* Draw outside the button by 1 pixel */
FrameRoundRect(&tempRect, 16, 16); /* Draw the outline */
PenSize(1, 1); /* Restore the pen size to the default value */
/* Draw a line, Drawn line1 */
PenSize(2,2); /* Set a wider pen width */
MoveTo(0,100); /* Horz,vert, Move to starting position */
LineTo(179,100); /* Horz,vert, Draw to the ending position */
PenSize(1,1); /* Back to default pen size */
U_Update_LIFE_WINDOW(WPtr_LIFE_WINDOW); /* Call the user update routine */
DrawDialog(WPtr_LIFE_WINDOW); /* Draw the rest of the controls */
SetPort(SavedPort); /* Restore the port that we saved at the start */
} /* End for the IF saying we are the window to update */
} /* End for the update procedure */
/* ======================================================= */
/* This procedures purpose is to open this window and set all */
/* of the initial conditions, such as default edit text. This routine */
/* calls the update routine to draw all non-controls. If this */
/* routine is already open when it is called again, then nothing */
/* is done (another copy is NOT opened). */
void Open_LIFE_WINDOW()
{
TEHandle ThisEditText;
DialogPeek TheDialogPtr;
Rect tempRect; /* Temporary rectangle variable */
short DType; /* Type of dialog item */
Handle DItem; /* Handle to the dialog item */
ControlHandle CItem; /* Control handle */
if (WPtr_LIFE_WINDOW == NIL)
{
WPtr_LIFE_WINDOW = GetNewDialog(Res_MD_LIFE_WINDOW, NIL, (Ptr)-1 );/* Bring in the dialog resource */
tempRect = WPtr_LIFE_WINDOW->portRect; /* Get window size, we will now center it */
tempRect.top = ((screenBits.bounds.bottom - screenBits.bounds.top) - (tempRect.bottom - tempRect.top)) / 2;/* Center vert */
tempRect.left = ((screenBits.bounds.right - screenBits.bounds.left) - (tempRect.right - tempRect.left)) / 2;/* Center Horz */
MoveWindow(WPtr_LIFE_WINDOW, tempRect.left, tempRect.top, TRUE);/* Now move the window to the proper position */
ShowWindow(WPtr_LIFE_WINDOW); /* Open a dialog box */
SelectWindow(WPtr_LIFE_WINDOW); /* Lets see it */
SetPort(WPtr_LIFE_WINDOW); /* Prepare to add conditional text */
TheDialogPtr = (DialogPeek)WPtr_LIFE_WINDOW; /* Get to the inner record */
ThisEditText = TheDialogPtr->textH; /* Get to the TE record */
HLock((Handle)ThisEditText); /* Lock it for safety */
(*ThisEditText)->txSize = 12; /* TE Point size */
TextSize(12); /* Window Point size */
(*ThisEditText)->txFont = systemFont; /* TE Font ID */
TextFont(systemFont); /* Window Font ID */
(*ThisEditText)->txFont = 0; /* TE Font ID */
(*ThisEditText)->fontAscent = 12; /* Font ascent */
(*ThisEditText)->lineHeight = 12 + 3 + 1; /* Font ascent + descent + leading */
HUnlock((Handle)ThisEditText); /* UnLock the handle when done */
/* Setup initial conditions */
U_Setup_LIFE_WINDOW(WPtr_LIFE_WINDOW); /* Call the user Open procedure */
}
else
SelectWindow(WPtr_LIFE_WINDOW); /* Lets see it */
} /* End of the Open procedure */
/* ======================================================= */
/* This procedures purpose is to close this window and clear */
/* the window pointer variable, this tells the other routines */
/* that this window is closed and may be opened again. */
void Close_LIFE_WINDOW(theWindow)
WindowPtr theWindow;
{
if ((theWindow == WPtr_LIFE_WINDOW) && (WPtr_LIFE_WINDOW != NIL ))/* Only close if it is us and we were open */
{ /* Start the close */
U_Close_LIFE_WINDOW(WPtr_LIFE_WINDOW); /* Call the user close routine */
DisposDialog(WPtr_LIFE_WINDOW); /* Close on the screen and Flush the dialog out of memory */
WPtr_LIFE_WINDOW = NIL; /* Make sure our other routines know that we are closed */
} /* End for the If saying it is us */
} /* End for the close routine */
/* ======================================================= */
/* This procedures purpose is to handle all actions, such as buttons */
/* being pressed. This is the real meat of this unit and is where the */
/* code is for acting upon the users actions. */
void Do_LIFE_WINDOW(theEvent, theWindow,itemHit)
EventRecord *theEvent;
WindowPtr theWindow;
short itemHit;
{
short Index; /* For looping */
Point myPt; /* For the local mouse position */
Boolean ExitDialog; /* Flag to close this dialog */
short DType; /* Type of dialog item */
Handle DItem; /* Handle to the dialog item */
Rect tempRect; /* Temporary rectangle */
ControlHandle CItem; /* Control handle */
short temp; /* temp integer */
ExitDialog = FALSE; /* Do not close the dialog yet */
if ((theEvent->what == mouseDown) && (WPtr_LIFE_WINDOW != NIL ))
{
SetPort(WPtr_LIFE_WINDOW); /* Set the port to our dialog */
myPt = theEvent->where; /* Get the position where the mouse was pressed */
GlobalToLocal(&myPt); /* Change from global to local location */
}
if (WPtr_LIFE_WINDOW != NIL)
{
if (theEvent->what == keyDown)
{
itemHit = 0; /* Default to no item hit */
temp = theEvent->message & charCodeMask;/* Get the character pressed */
if ((temp == 13) || (temp == 3)) /* See if CR or Enter */
itemHit = 1;
}
if ((WPtr_LIFE_WINDOW != NIL) && (WPtr_LIFE_WINDOW == theWindow))
{
myPt = theEvent->where; /* Get the position where the mouse was pressed */
GlobalToLocal(&myPt); /* Change from global to local location */
GetDItem(WPtr_LIFE_WINDOW, itemHit,&DType,&DItem,&tempRect);/* Get which item was pressed */
CItem = (ControlHandle)DItem; /* Change the pointer for getting to the control */
U_Hit_LIFE_WINDOW(WPtr_LIFE_WINDOW,itemHit,&ExitDialog,theEvent);/* Give the user the itemhit */
/* Handle it real time */
if (itemHit ==Res_Dlg_Continue) /* Handle the Button being pressed */
{
}
if (itemHit ==Res_Dlg_Quit) /* Handle the Button being pressed */
{
ExitDialog = TRUE; /* Close this dialog, exit */
}
} /* End of not NIL */
}
if (ExitDialog == TRUE) /* Do the close of the dialog */
{
Close_LIFE_WINDOW(WPtr_LIFE_WINDOW);
WPtr_LIFE_WINDOW = NIL; /* Clear it for future checks */
}
} /* End of procedure */